package com.ruoyi.cems.service.impl;

import java.util.List;

import com.ruoyi.base.domain.BaseFile;
import com.ruoyi.base.service.IBaseFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cems.mapper.BmsEmergencyManualMapper;
import com.ruoyi.cems.domain.BmsEmergencyManual;
import com.ruoyi.cems.service.IBmsEmergencyManualService;

/**
 * 应急手册;Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-24
 */
@Service
public class BmsEmergencyManualServiceImpl implements IBmsEmergencyManualService 
{
    @Autowired
    private BmsEmergencyManualMapper bmsEmergencyManualMapper;

    @Autowired
    private IBaseFileService baseFileService;

    /**
     * 查询应急手册;
     * 
     * @param ID 应急手册;主键
     * @return 应急手册;
     */
    @Override
    public BmsEmergencyManual selectBmsEmergencyManualByID(String ID)
    {
        return bmsEmergencyManualMapper.selectBmsEmergencyManualByID(ID);
    }

    /**
     * 查询应急手册;列表
     * 
     * @param bmsEmergencyManual 应急手册;
     * @return 应急手册;
     */
    @Override
    public List<BmsEmergencyManual> selectBmsEmergencyManualList(BmsEmergencyManual bmsEmergencyManual)
    {
        List<BmsEmergencyManual> bmsEmergencyManualList = bmsEmergencyManualMapper.selectBmsEmergencyManualList(bmsEmergencyManual);
        for (BmsEmergencyManual dbmsEmergencyManual : bmsEmergencyManualList){
            if (dbmsEmergencyManual.getFileId() != null){
                //获取应急文件
                dbmsEmergencyManual.setFile(baseFileService.selectBaseFileByID(dbmsEmergencyManual.getFileId()));
            }
        }
        return bmsEmergencyManualList;
    }

    /**
     * 新增应急手册;
     * 
     * @param bmsEmergencyManual 应急手册;
     * @return 结果
     */
    @Override
    public int insertBmsEmergencyManual(BmsEmergencyManual bmsEmergencyManual)
    {
        //更新文件信息
        BaseFile baseFile = baseFileService.selectBaseFileByID(bmsEmergencyManual.getFileId());
        if (baseFile != null){
            baseFile.setBizObjectId(bmsEmergencyManual.getID());
            baseFile.setModel("EmergencyManual");
            baseFile.setField("fileId");
            baseFileService.updateBaseFile(baseFile);
        }
        return bmsEmergencyManualMapper.insertBmsEmergencyManual(bmsEmergencyManual);
    }

    /**
     * 修改应急手册;
     * 
     * @param bmsEmergencyManual 应急手册;
     * @return 结果
     */
    @Override
    public int updateBmsEmergencyManual(BmsEmergencyManual bmsEmergencyManual)
    {
        //更新文件信息
        BaseFile baseFile = baseFileService.selectBaseFileByID(bmsEmergencyManual.getFileId());
        if (baseFile != null){
            baseFile.setBizObjectId(bmsEmergencyManual.getID());
            baseFile.setModel("EmergencyManual");
            baseFile.setField("fileId");
            baseFileService.updateBaseFile(baseFile);
        }
        return bmsEmergencyManualMapper.updateBmsEmergencyManual(bmsEmergencyManual);
    }

    /**
     * 批量删除应急手册;
     * 
     * @param IDs 需要删除的应急手册;主键
     * @return 结果
     */
    @Override
    public int deleteBmsEmergencyManualByIDs(String[] IDs)
    {
        return bmsEmergencyManualMapper.deleteBmsEmergencyManualByIDs(IDs);
    }

    /**
     * 删除应急手册;信息
     * 
     * @param ID 应急手册;主键
     * @return 结果
     */
    @Override
    public int deleteBmsEmergencyManualByID(String ID)
    {
        return bmsEmergencyManualMapper.deleteBmsEmergencyManualByID(ID);
    }
}
